import { Entity, Column, PrimaryGeneratedColumn, Index, ManyToOne, OneToMany } from "typeorm";
import { BaseEntity } from "./base";

@Entity({ name: "sys_menu" })
export class MenuModel extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100, type: "varchar", default: "", comment: "名称" })
  @Index()
  name: string;
  @Column({ name: "parent_name", length: 100, type: "varchar", default: "", comment: "父名称" })
  @Index()
  parentName: string;
  @Column({ length: 100, type: "varchar", default: "", comment: "连接地址" })
  url: string;
  @Column({ length: 100, type: "varchar", default: "", comment: "图标" })
  icon: string;
  @Column({ type: "int", nullable: true, default: 0, comment: "排序" })
  sort: number;
  @Column({ length: 100, type: "varchar", default: "", comment: "备注" })
  remark: string;
  @ManyToOne(() => MenuModel, menu => menu.children)
  parentId: MenuModel;
  @OneToMany(() => MenuModel, menu => menu.parentId)
  children: MenuModel[];
}
